package at.fhj.mobsecdev.cookit.model;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

public class Ingredient implements Serializable {
	private static final long serialVersionUID = -3463758613323304607L;

	private String food;
	
	private String amount;

	public String getFood() {
		return food;
	}

	public void setFood(String food) {
		this.food = food;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}
	
	@Override
	public String toString() {
		return food + ": " + amount;
	}
	
	/**
	 * Converts ingredient to JSON for sending it to the upload web service
	 * @return
	 */
	public JSONObject toJSON() {
		JSONObject jsonObject = new JSONObject();
		
		try
		{
			jsonObject.put("amount", getAmount());
			jsonObject.put("ingredient", getFood());
			
			return jsonObject;
		}
		catch(JSONException e)
		{
			e.printStackTrace();
			return new JSONObject();
		}
	}
}
